package com.atguigu.educms.controller;


import com.atguigu.commonutils.Result;
import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-09-08
 */
@RestController
@RequestMapping("/educms/banneradmin")
@CrossOrigin
public class BannerAdminController {

    @Resource
    private CrmBannerService bannerService;

    @GetMapping("/pageBanner/{page}/{limit}")
    public Result pageBanner(@PathVariable Long page,@PathVariable Long limit) {
        Page<CrmBanner> bannerPage = new Page<>(page,limit);
        bannerService.page(bannerPage,null);
        return Result.ok().data("items",bannerPage.getRecords()).data("total",bannerPage.getTotal());
    }

    @ApiOperation(value = "新增Banner")
    @PostMapping("/save")
    public Result save(@RequestBody CrmBanner banner) {
        bannerService.save(banner);
        return Result.ok();
    }
    @ApiOperation(value = "修改Banner")
    @PutMapping("/update")
    public Result updateById(@RequestBody CrmBanner banner) {
        bannerService.updateById(banner);
        return Result.ok();
    }
    @ApiOperation(value = "删除Banner")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable String id) {
        bannerService.removeById(id);
        return Result.ok();
    }
}

